package demo11;

import javax.management.StringValueExp;
import java.util.Scanner;

interface A {
    public String show();
}

class B implements A {
    public String show() {
        return "B";
    }
}

class C extends B {
    public String show() {
        return "C";
    }
}
class Test1 {
    public static void main23(String[] args) {
        A a = new B();
        B b = new C();
        A c = new C();
        System.out.println(a.show() + b.show() + c.show());
    }
}
class Base {
    public void method(){
        System.out.print ("Base method.");
    }

    public void methodB() {
    }
}
class Child extends Base{
    public void methodB(){
        System.out.print ("Child methodB.");
    }
}
class Sample {
    public static void main22(String[] args) {
        Base base= new Child();
        base.methodB();
    }
}
public class Test {
    public static void main21(String[] args) {
        int MyIntArray[] = { 10, 20, 30, 40, 50, 60, 70 };

        int s = 0;

        for (int i = 0; i < MyIntArray.length; i++)

            if (i % 2 == 1)

                s += MyIntArray[i];

        System.out.println(s);

    }
    public static void main20(String[] args) {
        String str ="To be or not to be";
        String[] result =str.split(" ");
        StringBuilder stringBuilder =new StringBuilder();
        for (String s1:result){
            StringBuilder stringBuilder1 =new StringBuilder(s1);
            stringBuilder1.reverse();
           stringBuilder.append(stringBuilder1).append(" ");
        }
        String lastFinish = stringBuilder.toString().trim();
        System.out.println(lastFinish);
    }
    public static void main19(String[] args) {
        Scanner scanner =new Scanner(System.in);
        String str =scanner.nextLine();
        int lowCount =0;
        int uppCount =0;
        int digitCount =0;
        for (int i = 0; i < str.length(); i++) {
            char ch =str.charAt(i);
            if(Character.isUpperCase(ch)){
                uppCount++;
            }else if(Character.isLowerCase(ch)){
                lowCount++;
            }else if(Character.isDigit(ch)){
                digitCount++;
            }
        }
        System.out.println("小写:"+lowCount+"大写:"+uppCount+"数字"+digitCount);
    }
    public static void main18(String[] args) {
        String s ="jdk";
        String s1=s.toUpperCase();
        System.out.println(s1.substring(1));
    }
    //检测字符串是否为回文
    public boolean isPalindrome(String s) {
        s = s.toLowerCase();
        int left =0;
        int right =s.length()-1;
        while(left<right){
            while(left<right&&!isNumberAndCharacter(s.charAt(left))){
                left++;
            }
            while(left<right&&!isNumberAndCharacter(s.charAt(right))){
                right--;
            }
            if(s.charAt(left)==s.charAt(right)){
                left++;
                right--;
            }else{
                return false;
            }
        }
        return true;
    }
    private  boolean isNumberAndCharacter(char ch){
        if(Character.isDigit(ch)||Character.isLetter(ch)){
            return true;
        }
        return false;
    }
    //第一个只出现一次的字符
    public int firstUniqChar(String s){
        int[] count =new int[26];
        for (int i = 0; i <s.length() ; i++) {
            char ch =s.charAt(i);
            count[ch-'a']++;
        }
        for (int i = 0; i < s.length(); i++) {
            char ch =s.charAt(i);
            if (count[ch-'a']==1){
                return i;
            }
        }
        return  -1;
    }
    //最后一个单词的长度
    public static void main17(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str =scanner.nextLine();
        //1.字符串的分割
        String[] s1 =str.split(" ");
        int len =s1[s1.length-1].length();
        System.out.println(len);
        //2.找到最后一个空格的坐标，然后截取空客后的坐标
        int index =str.lastIndexOf(" ");
        int len1 =str.substring(index+1).length();
        System.out.println(len1);
    }
    public static void main16(String[] args) {
        StringBuilder stringBuilder =new StringBuilder("avcdefsw");
        //stringBuilder.insert(3,"wentao");
       stringBuilder.reverse();//逆序
        System.out.println(stringBuilder);
    }
    public static void main15(String[] args) {
        long start = System.currentTimeMillis();
        String s = "";
        for(int i = 0; i < 10000; ++i){
            s += i;
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);
        start = System.currentTimeMillis();
        StringBuffer sbf = new StringBuffer("");
        for(int i = 0; i < 10000; ++i){
            sbf.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
        start = System.currentTimeMillis();
        StringBuilder sbd = new StringBuilder();
        for(int i = 0; i < 10000; ++i){
            sbd.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
    }
    public static void main14(String[] args) {
        //字符串的修改
        String s ="hello";
        s+=" world";
        System.out.println(s);//可以用但不推荐,效率比较低下
//        StringBuffer stringBuffer = new StringBuffer();
//        stringBuffer.append ("hello");
//        stringBuffer.append(" wentao");
//        String ret =stringBuffer.toString();
        StringBuilder stringBuilder =new StringBuilder();
        stringBuilder.append("hello");
        stringBuilder.append(" liaozijv");
        String ret =stringBuilder.toString();
        System.out.println(ret);
    }
    //String的不可变性
    public static void main13(String[] args) {
        String s ="liyongxing";
        final char[] array ={'l','i','y','x'};
        array[0] ='x';
//        array =new array[10];
    }
    public static void main12(String[] args) {
        String s ="   ab  cd ef   ";
        System.out.println(s);
        System.out.println(s.trim());//只会去除左右两边的空格
    }
    public static void main11(String[] args) {
        //字符串截取
        String s ="掌管自由的神001";
        System.out.println(s.substring(6));//001
        System.out.println(s.substring(0,6));//掌管自由的神
    }
    public static void main10(String[] args) {
        String s="198.168.0.1";
        String[] strings =s.split("\\.");
        for (int i =0;i<strings.length;i++){
            System.out.println(strings[i]);
        }
        String s1 ="ab\\cd\\ef";
        String[] strings1 =s1.split("\\\\");
        for (int i=0;i<strings.length;i++){
            System.out.println();
        }
    }
    //字符串拆分
    public static void main9(String[] args) {
        String s ="hello world hello bit";
        String[] ret =s.split(" ");
        for(String str: ret){
            System.out.println(str);
        }
        String s1 ="naem=wentao&age=18";
        //返回值 是数组
        //String [] strings =s1.split("&");
        String [] strings =s1.split("=|&");
        for (int i=0;i<strings.length;i++){
            System.out.println(strings[i]);
        }
    }
    public static void main8(String[] args) {
        //字符串替换
        String s ="abcdbbccddfffgg";
        String tmp =s.replace('b','l');
        System.out.println(tmp);
        tmp =s.replace("df","nm");
        System.out.println(tmp);
        tmp =s.replaceFirst("fg","oooo");
        System.out.println(tmp);
    }
    public static void main7(String[] args) {
        //字符串转数组
        String s ="hello";
        char[] ch =s.toCharArray();
        for (int i = 0; i < ch.length; i++) {
            System.out.println(ch [i]);
        }
        System.out.println();
        //数组转数组
        String s1 =new String(ch);
        System.out.println(s1);
        //格式化
        String s2 =String.format("%d-%d-%d",2025,4,13);
        System.out.println(s2);//2025-4-13
    }
    public static void main6(String[] args) {
        //大小写的转换
        String s1 ="hello";
        String s2 =s1.toUpperCase();
        System.out.println(s2);
        String s3 ="HEL老弟109lo";
        System.out.println(s3.toLowerCase());

    }
    public static void main5(String[] args) {
        //转化
        //数字转字符串
        String s =String.valueOf(12345);
        String s1 =String.valueOf(12.56);
        String s2 =String.valueOf(true);
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s);
        System.out.println("===========");
        // 字符串转数字
// 注意：Integer、Double等是Java中的包装类型，这个后面会讲到
        int data1 =Integer.parseInt("1234");
        double data2 =Double.parseDouble("12.65");
        System.out.println(data1+4);
        System.out.println(data2);
    }
    public static void main4(String[] args) {
        //找字符串中对应字符的下标
        String s1 = new String("abbbbccddff");
        System.out.println(s1.charAt(3));//b
        System.out.println(s1.indexOf('c'));//5
        System.out.println(s1.indexOf('c',6));//6
        System.out.println(s1.indexOf('d'));//7
        System.out.println(s1.indexOf('f',9));//9
        System.out.println(s1.lastIndexOf('a'));
        /*for (int i = 0; i < s1.length(); i++) {
            char ch =s1.charAt(i);
            System.out.println(ch);
        }*/
//        char ch =s1.charAt(5);
//        System.out.println(ch);
//        int[] array ={1,2,3,4,5};
//        System.out.println(array.length);
        System.out.println(s1.lastIndexOf('d',9));

    }
    public static void main3(String[] args) {
        String s1 =new  String("aeF");
        String s2 =new String("aef");
        //比较字符串的大小
        System.out.println(s1.compareTo(s2));//s1和s2比较
        //1、根据对应字符比较(ASCll值)
        //2、对应字符，无法比较出来 谁大，谁小 此时就要看长度
        System.out.println(s1.compareToIgnoreCase(s2));//8
        System.out.println();
    }
    public static void main2(String[] args) {
        String s1 =new String("hello");
        String s2 = new String("hello");
        String s3 =s1;
        System.out.println(s1==s2);//false
        System.out.println(s1==s3);//true
        System.out.println(s2==s3);//false
        System.out.println("=============");
        System.out.println(s1.equals(s2));//true
        System.out.println(s1.equals(s3));//true
        System.out.println(s2.equals(s3));//true
        System.out.println(s1.length());
        System.out.println(s2.length());
    }
    //字符串构造
    public static void main1(String[] args) {
        //就地初始化
        String s1 ="hello word";
        String str2 =new String("word");
        System.out.println(s1);
        //使用字符数组构造
        char[] array ={'a','b','c','d','e'};
        String str =new String(array);
        System.out.println(s1);
        System.out.println(str2);
        System.out.println(str);
    }
}
